package com.woniu.sentinel.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.swing.text.html.HTMLDocument;
import java.util.Random;

@RestController
@RequestMapping("/sent")
public class SentinelController {

    @SentinelResource(value = "sen", fallback = "test_fallback", blockHandler = "test_blockHandler")
    @GetMapping("/test")
    public String test(){
//        Random random = new Random();
//        if (random.nextInt(2) == 0) {
//            throw new RuntimeException();
//        }
        return "测试";
    }

    // 降级方法
    public String test_fallback(Throwable throwable){
        return "降级方法";
    }

    // 限流方法
    public String test_blockHandler(BlockException e){
        return "限流方法";
    }



}
